import 'dart:convert';

import 'package:fluro/fluro.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_common_app/data/recommend_playlist_data.dart';
import 'package:flutter_common_app/pages/song_calendar/song_calendar_detail_page.dart';
import 'package:flutter_common_app/pages/tab/index.dart';
import 'package:flutter_common_app/pages/login_page.dart';
import 'package:flutter_common_app/pages/playing_detail/playing_detail_page.dart';
import 'package:flutter_common_app/pages/playlist_detail/playlist_detail_page.dart';
import 'package:flutter_common_app/pages/recommend_daily_songs/recommend_daily_songs_page.dart';
import 'package:flutter_common_app/pages/splash_page.dart';
import 'package:flutter_common_app/pages/top_list/top_list_page.dart';
import 'package:flutter_common_app/pages/web_view/web_view_page.dart';

Handler rootHandler = Handler(
    handlerFunc: (BuildContext context, Map<String, List<String>> params) {
  return SplashPage();
});

Handler indexHandler = Handler(
    handlerFunc: (BuildContext context, Map<String, List<String>> params) {
  return IndexPage();
});

Handler loginHandler = Handler(
    handlerFunc: (BuildContext context, Map<String, List<String>> params) {
  return LoginPage();
});

Handler playlistDetailHandler = Handler(
    handlerFunc: (BuildContext context, Map<String, List<String>> params) {
  String data = params['data'].first;
  RecommendPlaylistData recommendPlaylistData =
      RecommendPlaylistData.fromJson(jsonDecode(data));
  return PlaylistDetailPage(recommendPlaylistData);
});

Handler playingDetailHandler =
    Handler(handlerFunc: (context, Map<String, List<String>> params) {
  return PlayingDetailPage();
});

Handler recommendDailySongsHandler =
    Handler(handlerFunc: (context, Map<String, List<String>> params) {
  return RecommendDailySongsPage();
});

Handler topListHandler =
    Handler(handlerFunc: (context, Map<String, List<String>> params) {
  return TopListPage();
});

Handler songCalendarDetailHandler =
    Handler(handlerFunc: (context, Map<String, List<String>> params) {
  return SongCalendarDetailPage();
});

Handler webViewHandler =
    Handler(handlerFunc: (context, Map<String, List<String>> params) {
  String url = params['url'].first;
  return WebViewPage(url);
});
